// 仪器分类相关 API
import request from '@/utils/request';
import { CategoryResponse } from '@/types/instrument';

export const categoryApi = {
  // 获取仪器分类树
  getCategoryTree(): Promise<CategoryResponse[]> {
    return request.get('/system/category/list');
  },

  // 获取扁平化分类列表
  getCategoryList(): Promise<CategoryResponse[]> {
    return request.get('/system/category/flat-list');
  },

  // 根据父级ID获取子分类
  getCategoriesByParentId(parentId: number): Promise<CategoryResponse[]> {
    return request.get(`/system/category/children/${parentId}`);
  },

  // 获取分类详情
  getCategoryDetail(id: number): Promise<CategoryResponse> {
    return request.get(`/system/category/${id}`);
  },

  // 创建分类（管理员功能）
  createCategory(data: {
    name: string;
    parentId?: number;
  }): Promise<CategoryResponse> {
    return request.post('/admin/category', data);
  },

  // 更新分类（管理员功能）
  updateCategory(id: number, data: {
    name: string;
    parentId?: number;
  }): Promise<CategoryResponse> {
    return request.put(`/admin/category/${id}`, data);
  },

  // 删除分类（管理员功能）
  deleteCategory(id: number): Promise<boolean> {
    return request.delete(`/admin/category/${id}`);
  },

  // 批量删除分类（管理员功能）
  batchDeleteCategories(ids: number[]): Promise<boolean> {
    return request.delete('/admin/category/batch', { data: { ids } });
  },

  // 获取分类统计信息
  getCategoryStats(): Promise<{
    totalCategories: number;
    topLevelCategories: number;
    instrumentCount: Record<number, number>;
    }> {
    return request.get('/system/category/stats');
  },
}; 